#!/usr/bin/python
# -*- coding: utf-8 -*-

import time
import MySQLdb

import datetime

conn = MySQLdb.Connection("172.16.7.58", "root", "researchsucks", "X", 3306)
conn.set_character_set("utf8");
cur = conn.cursor()

out = open('/home/chaojiansong/videobook/pop/ver1/track_data/' + time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) + '.stat', 'w')

cur.execute("select id, pv, totalcomment, fav, up, down, reference, pubdate from video_info where \
        pubdate<date('2011-11-23') and pubdate>=date('2011-11-22')")

for data in cur.fetchall():
    out.write('id: ' + data[0] + '\n')
    out.write('pv: ' + str(data[1]) + '\n')
    out.write('totalcomment: ' + str(data[2]) + '\n')
    out.write('fav: ' + str(data[3]) + '\n')
    out.write('up: ' + str(data[4]) + '\n')
    out.write('down: ' + str(data[5]) + '\n')
    out.write('reference: ' + str(data[6]) + '\n')
    out.write('pubdate: ' + str(data[7]) + '\n')

out.close()
cur.close()
conn.close()
